package com.esri.core.internal.tasks.ags.c;

import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.FeatureResult;
import com.esri.core.map.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class d extends com.esri.core.internal.tasks.d<Map<Long, FeatureResult>> {
    private static final long serialVersionUID = 1;

    public d(e eVar, String str, UserCredentials userCredentials) {
        super(eVar, str, userCredentials);
    }

    public d(e eVar, String str, UserCredentials userCredentials, TaskListener<Map<Long, FeatureResult>> taskListener) {
        super(eVar, str, userCredentials, taskListener);
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public Map<Long, FeatureResult> execute() throws Exception {
        JsonParser jsonParser = null;
        try {
            jsonParser = com.esri.core.internal.io.handler.h.a(this.serviceURL + "/queryRelatedRecords", this.actionInput.generateRequestParams(), getServiceCredentials());
            return a(jsonParser);
        } finally {
            if (jsonParser != null) {
                jsonParser.close();
            }
        }
    }

    public static final Map<Long, FeatureResult> a(JsonParser jsonParser) throws Exception {
        if (com.esri.core.internal.util.d.c(jsonParser)) {
            HashMap hashMap = new HashMap();
            ArrayList arrayList = null;
            SpatialReference spatialReference = null;
            String str = null;
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("spatialReference".equals(currentName)) {
                    spatialReference = SpatialReference.fromJson(jsonParser);
                } else if ("fields".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        arrayList = new ArrayList();
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            Field fromJson = Field.fromJson(jsonParser);
                            if (fromJson.getFieldType() == 80) {
                                str = fromJson.getName();
                            }
                            arrayList.add(fromJson);
                        }
                    }
                } else if ("relatedRecordGroups".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        b bVar = null;
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            long j = -1;
                            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                                String currentName2 = jsonParser.getCurrentName();
                                jsonParser.nextToken();
                                if ("objectId".equals(currentName2)) {
                                    j = jsonParser.getLongValue();
                                } else if ("relatedRecords".equals(currentName2)) {
                                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                        ArrayList arrayList2 = new ArrayList();
                                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                            arrayList2.add(a.a(jsonParser, spatialReference, str));
                                        }
                                        bVar = new b(arrayList2, arrayList);
                                    }
                                } else {
                                    jsonParser.skipChildren();
                                }
                            }
                            if (j != -1) {
                                hashMap.put(Long.valueOf(j), bVar);
                            }
                        }
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            return hashMap;
        }
        return null;
    }
}
